package com.yunji.app.cabinet;

import com.yunji.aggregate.model.dto.container.CabinetParam;
import com.yunji.aggregate.model.vo.container.CabinetViewVO;
import com.yunji.aggregate.service.ContainerAggregateService;
import com.yunji.cabinet.business.CabinetOperateBusiness;
import com.yunji.cabinet.domain.ContainerDO;
import com.yunji.cabinet.dto.CabinetBindDTO;
import com.yunji.cabinet.dto.CabinetCargoDTO;
import com.yunji.cabinet.dto.CabinetDTO;
import com.yunji.cabinet.vo.CabinetScanVO;
import com.yunji.common.annotation.RepeatSubmit;
import com.yunji.common.base.BaseController;
import com.yunji.common.base.response.Response;
import com.yunji.common.base.response.ResponseHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;


/**
 * @version 1.0
 * @Project: yunji-coffee
 * @Package com.yunji.app.user
 * @FileName GateWayScanCodeController.java
 * @Copyright Copyright © 2024 云集互联. All Rights Reserved
 * Company		com
 * @CreateTime 2024-04-12 15:30:48
 * @Description 货柜操作交互
 * @Modification Author                    History Time			Version				Description
 * --------------------------------------------------------------------------------
 * HuaAo				2024-04-12 15:30:48		1.0					1.0 Version
 * @since JDK 1.8.0_202
 */
@RestController
@Api(tags = "移动端-货柜操作")
@RequestMapping("/gateway/operate")
public class GateWayOperateController extends BaseController {
    @Resource
    CabinetOperateBusiness business;

    @Resource
    ContainerAggregateService aggregateService;

    @ApiOperation("1.员工端扫码判断是否有权限进行操作")
    @PostMapping("scanCodeAuthentication")
    public Response<CabinetScanVO> scanCodeAuthentication(@RequestParam("qrcode") String qrcode) {
        CabinetScanVO vo = business.selectCabinet(qrcode);
        return ResponseHelper.success(vo);
    }

    @ApiOperation("2.员工端扫码绑定货柜")
    @PostMapping("scanCodeBindContainer")
    @RepeatSubmit
    public Response<String> scanCodeBindContainer(@RequestBody @Valid CabinetBindDTO cabinet) {
        business.bindCabinet(cabinet);
        return ResponseHelper.success("绑定成功");
    }

    @ApiOperation("3.员工端扫码之后根据上传的序号打开对应格子")
    @PostMapping("scanCodeOpenContainer")
    @RepeatSubmit
    public Response<String> scanCodeOpenContainer(@RequestParam("qrcode") String qrcode, @RequestParam("ordinals") String ordinals) {
        return ResponseHelper.success(business.openedCabinet(qrcode, ordinals));
    }

    @ApiOperation("4.员工端扫码后关闭货柜接口")
    @PostMapping("scanCodeCloseContainer")
    public Response<String> scanCodeCloseContainer(@Valid @RequestBody CabinetCargoDTO dto) {
        return ResponseHelper.success(business.closedCabinet(dto));
    }

    @ApiOperation("5.员工扫码查看货柜")
    @PostMapping("scanCodeViewContainer")
    public Response<CabinetScanVO> scanCodeViewContainer(@RequestParam("qrcode") String qrcode) {
        return ResponseHelper.success(business.viewContainer(qrcode));
    }

    @ApiOperation("6.员工查看货柜列表")
    @GetMapping("viewContainerList")
    public Response<List<CabinetViewVO>> viewContainerList(CabinetParam param) {
        List<CabinetViewVO> list = aggregateService.viewContainerList(param);
        return ResponseHelper.successWithPage(list);
    }

    @ApiOperation("7.员工查看货柜详情")
    @PostMapping("viewContainerInfo")
    public Response<CabinetScanVO> viewContainerInfo(@RequestBody CabinetDTO dto) {
        return ResponseHelper.success(business.viewContainerInfo(dto));
    }

    @ApiOperation("8.员工修改货柜")
    @PostMapping("updateContainer")
    public Response<String> updateContainer(@RequestBody ContainerDO cabinet) {
        business.update(cabinet);
        return ResponseHelper.success("修改成功");
    }


    @ApiOperation("10.取出全部商品")
    @PostMapping("takeAllProduct")
    public Response<String> takeAllProduct(@RequestParam("containerId") Long containerId) {
        business.takeAllProduct(containerId);
        return ResponseHelper.success("取出成功");
    }

    @ApiOperation("11.取出单个商品")
    @PostMapping("takeOneProduct")
    public Response<String> takeOneProduct(@RequestParam("containerId") Long containerId, @RequestParam("ordinal") Integer ordinal) {
        business.takeOneProduct(containerId, ordinal);
        return ResponseHelper.success("去除成功");
    }

    @ApiOperation("12.解绑货柜")
    @PostMapping("unbindCabinet")
    public Response<String> unbindCabinet(@RequestParam("qrcode") String qrcode) {
        business.unbindCabinet(qrcode);
        return ResponseHelper.success();
    }

}